import Vue from 'vue'
import Vuex from 'vuex'  // 引入Vuex



Vue.use(Vuex)  // 应用Vuex插件

const actions = {
    isLogin(context, value) {
        context.commit('ISLOGIN', value)
    },
    noLogin(context, value) {
        context.commit('NOLOGIN', value)
    },
    changeName(context,value){
        context.commit('CHANGENAME', value)
    },
    setEndTime(context, value){
        context.commit('SETENDTIME', value)
    }

}


const mutations = {
    ISLOGIN(state, value) {
        state.isLogin = true
    },
    NOLOGIN(state, value) {
        state.isLogin = false
        state.userName = ''
        state.endTime = ''
        localStorage.removeItem('isLogin')
        localStorage.removeItem('userName')
        localStorage.removeItem('endTime')
    },
    CHANGENAME(state, value){
        state.userName = value
    },
    SETENDTIME(state, value){
        state.endTime = value
    },
    
}


const state = {
    isLogin: false,
    userName:'',
    endTime:''
}

// 创建并暴露store
export default new Vuex.Store({
    actions,
    mutations,
    state,
}
)